//
//  UITextField+UITextFieldExtend.m
//  etionUI
//
//  Created by wu jingxing on 12-12-11.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "UITextFieldExtend.h"

#import "OperationQueueShell.h"

@implementation UITextField (UITextFieldExtend)

-(void)findClearBtn:(void(^)(UIButton* btn))findblock
{
    for(UIView* v in self.subviews)
    {
        if([v isMemberOfClass:[UIButton class]])
        {
            UIButton* btn=(UIButton*)v;
            
            findblock(btn);
            
            break;
        }
    }
}

-(void)_exchangeClearBtnClearResponse:(SEL)response
{
    [self findClearBtn:^(UIButton *btn)
    {
        NSSet* s=[btn allTargets];
        if([s allObjects]>0)
        {
            id textfield=[[s allObjects]objectAtIndex:0];
            NSString *fun = [NSString stringWithFormat:@"%@%@%@",@"_clear",@"Button",@"Clicked:"];
            [btn removeTarget:textfield action:NSSelectorFromString(fun) forControlEvents:UIControlEventTouchUpInside];
        }
        [btn addTarget:self action:response forControlEvents:UIControlEventTouchUpInside];
    }];
}

-(void)exchangeClearBtnClearResponse:(SEL)response
{
    DispatchMainThreadSyncAfterDelay(0.5,^
    {
        [self _exchangeClearBtnClearResponse:response];
    });
}

-(void)setSzTag:(NSString *)szTag
{
   [self setAssociatedRetainNonatomicValue:szTag withKey:"szTag"];
}

-(NSString*)szTag
{
    return [self associatedValueForKey:"szTag"];
}

@end
